﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace LinearAlgebra
{
    public partial class VectorBasisChangeDialog : Form
    {
        float b1X;
        float b1Y;

        float b2X;
        float b2Y;

        public VectorBasisChangeDialog(float stdX, float stdY, float b1X, float b1Y, float b2X, float b2Y)
        {
            this.b1X = b1X;
            this.b1Y = b1Y;

            this.b2X = b2X;
            this.b2Y = b2Y;

            InitializeComponent();
            float determinate = b1X * b2Y - b1Y * b2X;

            float inverseB1X = b2Y / determinate;
            float inverseB2Y = b1X / determinate;

            float inverseB2X = -b2X / determinate;
            float inverseB1Y = -b1Y / determinate;

            float resultX = stdX*inverseB1X + stdY*inverseB2X;
            float resultY = stdX*inverseB1Y + stdY*inverseB2Y;      
            
            
            StdX1.Text = stdX.ToString("0.00", CultureInfo.InvariantCulture);
            StdX2.Text = stdX.ToString("0.00", CultureInfo.InvariantCulture);
            B1X1.Text = b1X.ToString("0.00", CultureInfo.InvariantCulture);
            B2X1.Text = b2X.ToString("0.00", CultureInfo.InvariantCulture);
            B1X2.Text = b1X.ToString("0.00", CultureInfo.InvariantCulture);
            B2X2.Text = b2X.ToString("0.00", CultureInfo.InvariantCulture);
            Inv11_1.Text = inverseB1X.ToString("0.00", CultureInfo.InvariantCulture);
            Inv12_1.Text = inverseB2X.ToString("0.00", CultureInfo.InvariantCulture);
            Inv11_2.Text = inverseB1X.ToString("0.00", CultureInfo.InvariantCulture);
            Inv12_2.Text = inverseB2X.ToString("0.00", CultureInfo.InvariantCulture);
            ResultX.Text = resultX.ToString("0.00", CultureInfo.InvariantCulture);

            StdY1.Text = stdY.ToString("0.00", CultureInfo.InvariantCulture);
            StdY2.Text = stdY.ToString("0.00", CultureInfo.InvariantCulture);
            B1Y1.Text = b1Y.ToString("0.00", CultureInfo.InvariantCulture);
            B2Y1.Text = b2Y.ToString("0.00", CultureInfo.InvariantCulture);
            B1Y2.Text = b1Y.ToString("0.00", CultureInfo.InvariantCulture);
            B2Y2.Text = b2Y.ToString("0.00", CultureInfo.InvariantCulture);
            Inv21_1.Text = inverseB1Y.ToString("0.00", CultureInfo.InvariantCulture);
            Inv22_1.Text = inverseB2Y.ToString("0.00", CultureInfo.InvariantCulture);
            Inv21_2.Text = inverseB1Y.ToString("0.00", CultureInfo.InvariantCulture);
            Inv22_2.Text = inverseB2Y.ToString("0.00", CultureInfo.InvariantCulture);
            ResultY.Text = resultY.ToString("0.00", CultureInfo.InvariantCulture);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            InverseExplain2DDialog form = new InverseExplain2DDialog(b1X, b1Y, b2X, b2Y);
            form.Show( );
        }

        private void button8_Click(object sender, EventArgs e)
        {
            Close( );
        }
    }
}
